package our.pack;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Projection;

class MapLineOverlay extends com.google.android.maps.Overlay {
	private ArrayList <GeoPoint> mRoute;
	private int mRouteIndex;
	private final String TAG = "MapLineOverlay";
	private Projection projection;


	public MapLineOverlay () {
		mRoute = new ArrayList <GeoPoint>();
		mRouteIndex = 0;


	}
	@Override
	public void draw(Canvas canvas, MapView mv, boolean shadow) {
		super.draw(canvas, mv, shadow);
		assert canvas != null : "null canvas";
		assert mv != null : "null mapview";
		assert shadow == true || shadow == false : "shadow must have a boolean";

		Paint paint = new Paint();
		paint.setColor(Color.GREEN);
		paint.setStyle(Style.FILL_AND_STROKE);
		paint.setStrokeWidth(2);
		paint.setAntiAlias(true);

		// ----- draw line ----- //
		Projection projection = mv.getProjection();
		Path path = new Path();

		for (GeoPoint g : mRoute){
			Log.i(TAG, "Current GeoPoint is: " + g.getLatitudeE6() + "" +  g.getLongitudeE6() );
		}
		if (mRoute.size() >= 1)
		{
			for (int i = 0; i < (mRoute.size() - 1); i++) {

				Point from = new Point();
				Point to   = new Point();
				projection.toPixels(mRoute.get(i), from);
				Log.d(TAG, "point from" + mRoute.get(i));
				projection.toPixels(mRoute.get(i+1), to);
				Log.d(TAG, "point to" + mRoute.get(i+1));

				path.moveTo(to.x, to.y);
				path.lineTo(from.x, from.y);
				canvas.drawPath(path, paint);
			}
		}}



	public int getSize(){
		return mRoute.size();
	}
	public void clear(){
		mRoute.clear();
		
	}



	public void addPoint(GeoPoint g){
		assert mRoute != null : "mRoute = null";

		Log.i(TAG, "Adding point" + g.toString()+ "Current size = " + mRoute.size());
		mRoute.add(g);
		Log.i(TAG, "Size is now = " + mRoute.size());
		mRouteIndex++;
	}










}